package com.dd.support;

import java.io.UnsupportedEncodingException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.websocket.common.Opcode;
import org.tio.websocket.common.WsPacket;

public class WsRequest extends WsPacket {
	private static Logger log = LoggerFactory.getLogger(WsRequest.class);

	private static final long serialVersionUID = 963847148301021559L;
	
	public static WsRequest fromText(String text, String charset) {
		WsRequest WsRequest = new WsRequest();
		try {
			WsRequest.setBody(text.getBytes(charset));
		} catch (UnsupportedEncodingException e) {
			log.error(e.toString(), e);
		}
		WsRequest.setWsOpcode(Opcode.TEXT);
		return WsRequest;
	}
	
	public static WsRequest fromBytes(byte[] bytes) {	
		WsRequest WsRequest = new WsRequest();
		WsRequest.setBody(bytes);
		WsRequest.setWsOpcode(Opcode.BINARY);
		return WsRequest;
	}
}